package com.ctf.soft.ms.service.manage.impl;

import com.ctf.soft.ms.dao.mapper.manage.ResourceMapper;
import com.ctf.soft.ms.dao.model.manage.Resource;
import com.ctf.soft.ms.service.impl.BaseService;
import com.ctf.soft.ms.service.manage.IResourceService;
import com.ctf.soft.ms.utils.ResourceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 名称： ResourceServiceImpl<br>
 * 描述： 第三方资源配置业务处理实现类<br>
 * 最近修改时间：2015/7/31 13:26<br>
 * 修改说明：
 *
 * @author jiajl
 */
@Service
public class ResourceServiceImpl extends BaseService<Resource> implements IResourceService {

    @Autowired
    private ResourceMapper resourceMapper;

    public List<Resource> loadPageList(Map<String, Object> map) {
        int page = Integer.valueOf(map.get("page").toString());
        int rows = Integer.valueOf(map.get("rows").toString());
        int beginRowNum = (page - 1) * rows;
        int endRowNum = page * rows;
        map.put("beginRowNum", beginRowNum);
        map.put("endRowNum", endRowNum);
        map.put("db", ResourceUtil.getString("DATA_ALIAS"));
        return resourceMapper.queryForPageList(map);
    }

    public int getPageCount(Map<String, Object> map) {
        return resourceMapper.queryForPageCount(map);
    }


    public Resource getByAppCode(String appCode) {
        return resourceMapper.selectByAppCode(appCode);
    }

    @Override
    public Resource selectByOriginId(String originId) {
        Resource r = new Resource();
        r.setAppOriginId(originId);
        return resourceMapper.selectOne(r);
    }

}
